//package com.websocet.interceptor;
//
///**
// * @Author: 陈玉鹏
// * @Description: TODO
// * @DateTime: 2023/7/2 18:13
// */
//import com.websocet.domain.BaseResponse;
//import com.websocet.utils.EncryptionUtils;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@RestControllerAdvice
//public class ResponseEncryptionAdvice implements ResponseBodyAdvice<Object> {
//
//    @Override
//    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
//        // 支持所有类型的返回值
//        return true;
//    }
//
//    @Override
//    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
//                                  Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
//                                  ServerHttpResponse response) {
//        // 对返回值进行加密处理
////        if (body != null) {
////            String encryptedData = EncryptionUtils.encrypt(body.toString());
////            Map<String,String> map = new HashMap<>();
////            map.put("code","200");
////            map.put("data",encryptedData);
////            return map;
////        }
//       if (body instanceof BaseResponse) {
//           Object encryptedData = EncryptionUtils.encrypt((String) ((BaseResponse<?>) body).getData());
//           ((BaseResponse<?>) body).setData(encryptedData);
//            return body;
//        } else if (body == null) {
//            return BaseResponse.ok();
//        } else {
//            return BaseResponse.ok(EncryptionUtils.encrypt(body.toString()));
//        }
//    }
//}
